﻿@using K3Cloud.WebApi.Core.IoC.DataEntity
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"]</title>
    <link rel="stylesheet" href="/layui/css/layui.min.css" />
</head>
<body>

    <div id="tableSearch"></div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table1" lay-filter="table1"></table>
        </div>
    </div>
    <script type="text/html" id="menu-toolbar">
        <fieldset class="layui-elem-field layui-field-title">
         <legend>@ViewData["Title"]</legend>
        </fieldset>
    </script>

    <script src="/layui/layui.min.js"></script>

    <script>
        layui.config({ base: '/layui_exts/' }).extend({
            dynamicCondition: 'dynamicCondition/dynamicCondition'
        }).use(['table', 'layer', 'form', 'dynamicCondition'], function () {
            let form = layui.form;
            let $ = layui.$;
            let layer = layui.layer;
            let table = layui.table;
            let dynamicCondition = layui.dynamicCondition;
            var fields = @Html.Raw(ViewBag.PyList);
            var jsonData ={};
            jsonData.FieldKeys = '@Html.Raw(ViewBag.Fields)';
            var dc = dynamicCondition.create({
                type: "complex"
                , fields: fields[0]
                , conditionTextId: "#tableSearch"
                , requestDataType: "json"
                , popupBtnsWidth: 350
                , popupShowQueryBtn: true
                , unpopupBtnswidth: 350
                , unpopupShowAddBtn: true
                , nestedQuery: false
                , opsMap: {
                    "equal": "等于", "like": "包含", "between": "范围"
                    , "start": "左包含", "end": "右包含", "notlike": "不包含", "unequal": "不等于", "empty": "为空", "notempty": "不为空", "greater_than": "大于", "less_than": "小于", "in": "IN", "notin": "Not IN"
                }
                , opsList: ["like", "start", "end", "notlike", "equal", "unequal", "empty", "notempty", "between", "greater_than", "less_than", "in", "notin"]
                , queryCallBack: function (requestData) {
                    jsonData = dynamicCondition.getInstance().buildRequestData();
                    jsonData.FieldKeys = '@Html.Raw(ViewBag.Fields)';
                    table.reload('table1', {
                        page: {
                            curr: 1
                        }
                        , method: 'post'
                        , where: jsonData
                    }, 'data');
                }
            });
            
            var resData = table.render({
                elem: '#table1'
                , id: 'table1'
                , url: '/Home/Query?FormId=@ViewBag.FormId'
                , method: 'post'
                , where: jsonData
                , cellMinWidth: 80
                , skin: 'line'
                , limits: [10, 50, 100, 500, 2000]
                , title: '@ViewData["Title"]'
                , toolbar: '#menu-toolbar'
                , defaultToolbar: ['filter', {
                    title: '引出Excel',
                    layEvent: 'excel',
                    icon: 'layui-icon-export'
                }]
                , cols: fields
                , page: true
                , totalRow: true
            });

            table.on('toolbar(table1)', function (obj) {
                if (obj.event === 'excel') {
                    window.location.href = '/Home/Export';
                }
            });

        });

    </script>

</body>
</html>